﻿using System;
using System.IO;
using System.Linq;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using Resn.WhuPub.BIL;
using System.Collections.Generic;
using Resn.WhuPub.DAL;
using Resn.WhuPub.DML;

namespace Resn.WhuPub.BLL
{
        /// <summary>
        /// 实现联系人管理器的属性和方法
        /// </summary>
        public class ContactManager:IContactManager
        {
                #region 属性

                private static ContactManager _instance;

                /// <summary>
                /// 获取学校/公司管理器实例
                /// </summary>
                /// <value>
                /// 学校/公司管理器实例
                /// </value>
                public static ContactManager Instance
                {
                        get { return  _instance??(_instance = new ContactManager()); }
                }


                /// <summary>
                /// 获取联系人集合
                /// </summary>
                /// <value>
                /// 联系人集合
                /// </value>
                public List<IContact> Contacts
                {
                        get
                        {
                                var models = DBStorage.Instance.Select<ContactModel>();

                                var categorys = new List<IContact>();

                                models.ForEach(i => categorys.Add(new Contact(i)));

                                return categorys;
                        }
                }
                #endregion

                #region 方法



                /// <summary>
                /// 创建联系人
                /// </summary>
                /// <param name="name">名称</param>
                /// <param name="code">代码</param>
                /// <param name="categoryLevel">层次</param>
                /// <returns>
                /// 创建的联系人对象
                /// </returns>
                public IContact CreateContact(string departmentId, string name, string title = "", string duty = "", string telephone = "",
                                       string qq = "", string email = "", bool isOwnAuthor = false, string memo = "")
                {
                        var model = new ContactModel
                        {
                                Id = Guid.NewGuid().ToString(),
                                Name = name,
                        };

                        return new Contact(model);
                }


                

                #endregion
        }
}